﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

/// <summary>
/// Summary description for ItemManager
/// </summary>
public class SaleManager
{
    private List<ERPSIA.DocDetail> _orderDetails;
    private double _taxAmount;
    private double _subtotalAmount;

    public SaleManager()
    {
        _orderDetails = new List<ERPSIA.DocDetail>();
        _taxAmount = 0;
        _subtotalAmount = 0;
    }
    
    public void AddDetail (ERPSIA.Item item, ERPSIA.StoreRoom store, double quantity, double unitCost, ERPSIA.Tax tax)
    {
        ERPSIA.DocDetail newDetail = new ERPSIA.DocDetail();
        newDetail.Item = item;
        newDetail.Quantity = quantity;
        newDetail.UnitCost = unitCost;
        newDetail.Tax = tax;
        newDetail.StoreRoom = store;
        _orderDetails.Add(newDetail);
        _subtotalAmount += Math.Round(unitCost * quantity, 2);
        _taxAmount += Math.Round(unitCost * quantity * tax.Porcentaje, 2);
    }

    public void RemoveDetail(int index)
    {
        ERPSIA.DocDetail detail = _orderDetails[index];
        _subtotalAmount -= Math.Round(detail.Quantity * detail.UnitCost, 2);
        _taxAmount -= Math.Round(detail.Quantity * detail.UnitCost * detail.Tax.Porcentaje, 2);
        _orderDetails.RemoveAt(index);
    }

    public ERPSIA.DocDetail[] GetDetails()
    {
        return _orderDetails.ToArray();
    }

    public double TaxAmount
    {
        get { return _taxAmount; }
    }

    public double SubTotalAmount
    {
        get { return _subtotalAmount; }
    }
}